﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using LPV_POS.In;
using LPV_POS;
using LPV_POS.Module;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Ellic;


class Mod_inbill_tatcabaocao
{     
    //Boolean bInComPort = false;
    DataTable tb = null;
    string tencongty = "";
    string dienthoai = "";
    string diachi = "";
    public void f_baocaodoanhthu_tatca(DataSet ds, string fromdate, string todate, decimal tienmat, decimal the)//, string makho, Boolean loaibaocao
    {
        try
        {
            //System.Windows.Forms.Cursor = System.Windows.Forms.Cursors.WaitCursor;            
            ////////////////////////////////

            Mod_header_report header_report = new Mod_header_report();
            tb = header_report.f_selectheaderreport();
            if (tb.Rows.Count > 0)
            {
                tencongty = tb.Rows[0]["HEADER"] + "";
                dienthoai = tb.Rows[0]["PHONE"] + "";
                diachi = tb.Rows[0]["ADDRESS"] + "";
            }
            //print_usb BIEN_NHAN
            thuvien tv = new thuvien();
            DataTable tbBN = tv.SP_SelectDataTable("sp_DM_MAYIN_BIENNHAN", null, null);
            DataView dv = tbBN.DefaultView;
            dv.Sort = "COMNAME";
            int vitri = dv.Find(new object[] { "USB"});
            int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
            int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
            if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)            
            //if (!bInComPort)
            {
                #region "in bill tieng viet"
                bc_BaoCaoTongHop rpt = new bc_BaoCaoTongHop();

                //ds.WriteXmlSchema(@"D:\Project\LPV-POS\LPV-POS\Baocao\ds_BaoCaoTongHop.xsd");

                rpt.DataDefinition.FormulaFields["tencongty"].Text = "'" + tencongty + "'";
                rpt.DataDefinition.FormulaFields["dienthoai"].Text = "'" + dienthoai + "'";
                rpt.DataDefinition.FormulaFields["diachi"].Text = "'" + diachi + "'";
                rpt.DataDefinition.FormulaFields["ngayin"].Text = "'" + "In báo cáo ngày " + DateTime.Today.ToString("dd/MM/yyyy") + "'";
                
                rpt.Subreports["rptbaocaotonghop_sub1"].SetDataSource(ds.Tables[1]);
                rpt.Subreports["rptbaocaotonghop_sub3"].SetDataSource(ds.Tables[3]);
                rpt.Subreports["rptbaocaotonghop_sub5"].SetDataSource(ds.Tables[5]);
                rpt.Subreports["rptbaocaotonghop_sub7"].SetDataSource(ds.Tables[7]);
                rpt.Subreports["rptbaocaotonghop_sub9"].SetDataSource(ds.Tables[9]);

                #region "   bao cao doanh thu"
                decimal iTHANHTIENTRUOC = 0;
                decimal iTHANHTIEN = 0;
                decimal iCHIECKHAU = 0;
                decimal iVat = 0;
                decimal iSERVICE_CHARGE = 0;
                decimal iPHUTHUKHAC = 0;
                decimal iKHUYENMAI = 0;
                decimal iTIENTIP = 0;
                decimal iTONGTHU = 0;
                decimal iTONGCHI = 0;
                decimal iCONGNO = 0;
                decimal iDatCoc = 0;
                decimal iDatCoc_Tru = 0;
                //
                #region "   "
                decimal.TryParse(ds.Tables[0].Rows[0]["THANHTIENTRUOC"] + "", out iTHANHTIENTRUOC);
                decimal.TryParse(ds.Tables[0].Rows[0]["THANHTIEN"] + "", out iTHANHTIEN);
                decimal.TryParse(ds.Tables[0].Rows[0]["CHIECKHAU"] + "", out iCHIECKHAU);

                decimal.TryParse(ds.Tables[0].Rows[0]["Vat"] + "", out iVat);
                decimal.TryParse(ds.Tables[0].Rows[0]["SERVICE_CHARGE"] + "", out iSERVICE_CHARGE);
                decimal.TryParse(ds.Tables[0].Rows[0]["PHUTHUKHAC"] + "", out iPHUTHUKHAC);
                decimal.TryParse(ds.Tables[0].Rows[0]["KHUYENMAI"] + "", out iKHUYENMAI);
                decimal.TryParse(ds.Tables[0].Rows[0]["TIENTIP"] + "", out iTIENTIP);
                decimal.TryParse(ds.Tables[0].Rows[0]["TONGTHU"] + "", out iTONGTHU);
                decimal.TryParse(ds.Tables[0].Rows[0]["TONGCHI"] + "", out iTONGCHI);
                decimal.TryParse(ds.Tables[0].Rows[0]["CONGNO"] + "", out iCONGNO);
                if (ds.Tables[0].Columns.Contains("DatCoc"))
                    decimal.TryParse(ds.Tables[0].Rows[0]["DatCoc"] + "", out iDatCoc);
                else
                    iDatCoc = 0;

                if (ds.Tables[0].Columns.Contains("DatCoc_Tru"))
                    decimal.TryParse(ds.Tables[0].Rows[0]["DatCoc_Tru"] + "", out iDatCoc_Tru);
                else
                    iDatCoc_Tru = 0;
                #endregion
                //
                rpt.DataDefinition.FormulaFields["lbel_congno"].Text = "'" + iCONGNO.ToString("N0") + "'";

                rpt.DataDefinition.FormulaFields["lbel_datcoc"].Text = "'" + iDatCoc.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_datcoc_tru"].Text = "'" + iDatCoc_Tru.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_giamgia_1"].Text = "'" + iCHIECKHAU.ToString("N0") + "'";

                rpt.DataDefinition.FormulaFields["lbel_khuyenmai"].Text = "'" + iKHUYENMAI.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_phuthu_2"].Text = "'" + iPHUTHUKHAC.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_thuedichvu_2"].Text = "'" + iSERVICE_CHARGE.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_tienchi_2"].Text = "'" + iTONGCHI.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_tienthu_2"].Text = "'" + iTONGTHU.ToString("N0") + "'";

                rpt.DataDefinition.FormulaFields["lbel_tientip_2"].Text = "'" + iTIENTIP.ToString("N0") + "'";

                rpt.DataDefinition.FormulaFields["lbel_tongcongchuatanggiam"].Text = "'" + iTHANHTIENTRUOC.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_tongcongdagiamgia"].Text = "'" + (iTHANHTIENTRUOC - iCHIECKHAU).ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbel_vat_2"].Text = "'" + iVat.ToString("N0") + "'";

                decimal dc_tm = tienmat + iTONGTHU - iTONGCHI + iDatCoc;

                rpt.DataDefinition.FormulaFields["lbl_tienmat"].Text = "'" + dc_tm.ToString("N0") + "'";
                rpt.DataDefinition.FormulaFields["lbl_thetratruoc"].Text = "'" + the + "'";

                string sab = (iTHANHTIENTRUOC
                                                - iCHIECKHAU
                                                + iVat
                                                + iSERVICE_CHARGE
                                                + iPHUTHUKHAC
                                                - iKHUYENMAI
                                                + iTIENTIP
                                                + iTONGTHU
                                                - iTONGCHI
                                                - iCONGNO
                                                + iDatCoc
                                                - iDatCoc_Tru
                                                ).ToString("N0");

                rpt.DataDefinition.FormulaFields["lbel_datanggiam"].Text = "'" + sab + "'";
                rpt.DataDefinition.FormulaFields["lbel_tientrongket"].Text = "'" + sab + "'";

                #region "   temp"
                //foreach (System.Windows.Forms.Control ctr in panelControl1.Controls)
                //{
                //    if (ctr.Name == "lbel_congno")
                //        rpt.DataDefinition.FormulaFields["lbel_congno"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_datanggiam")
                //        rpt.DataDefinition.FormulaFields["lbel_datanggiam"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_datcoc")
                //        rpt.DataDefinition.FormulaFields["lbel_datcoc"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_datcoc_tru")
                //        rpt.DataDefinition.FormulaFields["lbel_datcoc_tru"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_giamgia_1")
                //        rpt.DataDefinition.FormulaFields["lbel_giamgia_1"].Text = "'" + ctr.Text + "'";

                //    else if (ctr.Name == "lbel_khuyenmai")
                //        rpt.DataDefinition.FormulaFields["lbel_khuyenmai"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_phuthu_2")
                //        rpt.DataDefinition.FormulaFields["lbel_phuthu_2"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_thuedichvu_2")
                //        rpt.DataDefinition.FormulaFields["lbel_thuedichvu_2"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_tienchi_2")
                //        rpt.DataDefinition.FormulaFields["lbel_tienchi_2"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_tienthu_2")
                //        rpt.DataDefinition.FormulaFields["lbel_tienthu_2"].Text = "'" + ctr.Text + "'";

                //    else if (ctr.Name == "lbel_tientip_2")
                //        rpt.DataDefinition.FormulaFields["lbel_tientip_2"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_tientrongket")
                //        rpt.DataDefinition.FormulaFields["lbel_tientrongket"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_tongcongchuatanggiam")
                //        rpt.DataDefinition.FormulaFields["lbel_tongcongchuatanggiam"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_tongcongdagiamgia")
                //        rpt.DataDefinition.FormulaFields["lbel_tongcongdagiamgia"].Text = "'" + ctr.Text + "'";
                //    else if (ctr.Name == "lbel_vat_2")
                //        rpt.DataDefinition.FormulaFields["lbel_vat_2"].Text = "'" + ctr.Text + "'";
                #endregion
                //DevExpress.XtraEditors.PanelControl panelControl1

                //}
                #endregion

                #region "   PrinterDefault"
                System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                string sPrinterDefault = cls.PrinterName;
                rpt.PrintOptions.PrinterName = sPrinterDefault;
                #endregion
                if (new cpublic().Registry_Get("chkCrystalReport_Display") + "" == "True")
                {
                    mh_View frm = new mh_View(rpt);
                    frm.Show();
                }
                #endregion
                rpt.PrintToPrinter(0, true, 1, 100);
                rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
            }
            else
            {
                #region "   In Com Port"
                // Khởi tao class in bill 2:
                PrintCOMs oPrintCOMs = new PrintCOMs(PrintCOMs.Print_Type.Print_BILL);
                SerialPort_LPV[] aSerialPort_LPV = oPrintCOMs.Print_Start();

                foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                {
                    if (oSerialPort_LPV != null)
                    {
                        #region "   1.HEADER"
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO TAT CA DOANH THU", "", "", "");

                        if (tencongty != "")
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                        if (dienthoai != "")
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                        if (diachi != "")
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        if (fromdate == todate)
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, fromdate, "", "", "");
                        else
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, fromdate + "-" + todate, "", "", "");
                        #endregion

                        #region "   2.BAO CAO NHOM CHU HANG HOA - tb = ds.Tables[1]"
                        //lay dataset cua doanh thu theo nhom chu
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO NHOM CHU HANG HOA", "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, this.f_splitString3Column("Nhom chu", "Thanh tien  ", "Tien mat"), "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                        //========================================================
                        //lay dataset cua doanh thu theo nhom chu
                        tb = null;
                        tb = ds.Tables[1]; // in bill nhom chu
                        if (tb.Rows.Count > 0)
                        {
                            for (int i = 0; i < tb.Rows.Count; i++)
                            {
                                int iTHANHTIENTRUOC = 0;
                                int.TryParse(tb.Rows[i]["THANHTIENTRUOC"] + "", out iTHANHTIENTRUOC);
                                int iTIENMAT = 0;
                                int.TryParse(tb.Rows[i]["TIENMAT"] + "", out iTIENMAT);
                                float iTYLE = 0;
                                float.TryParse(tb.Rows[i]["TYLE"] + "", out iTYLE);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal,
                                                            this.f_splitString3Column(tb.Rows[i]["NHOMCHU"] + "", iTHANHTIENTRUOC.ToString("N0") , iTIENMAT.ToString("N0")));
                                if (i != tb.Rows.Count - 1)
                                    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                            }
                        }
                        #endregion

                        #region "   3.BAO CAO NHOM HANG - tb = ds.Tables[3]"
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        tb = null;
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO NHOM HANG", "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, this.f_splitString3Column("Nhom hang", "Thanh tien  ", "Tien mat"), "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                        tb = ds.Tables[3]; // nhom hang hoa
                        if (tb.Rows.Count > 0)
                        {
                            string sNHOMHANG = "";
                            cpublic ocpublic = new cpublic();
                            for (int i = 0; i < tb.Rows.Count; i++)
                            {
                                sNHOMHANG = tb.Rows[i]["NHOMHANG"] + "";
                                int iTHANHTIENTRUOC = 0;
                                int.TryParse(tb.Rows[i]["THANHTIENTRUOC"] + "", out iTHANHTIENTRUOC);
                                int iTIENMAT = 0;
                                int.TryParse(tb.Rows[i]["TIENMAT"] + "", out iTIENMAT);
                                float iTYLE = 0;
                                float.TryParse(tb.Rows[i]["TYLE"] + "", out iTYLE);
                                ///
                                string[] aNHOMHANG = ocpublic.splitString(sNHOMHANG, 32 - iTHANHTIENTRUOC.ToString("N0").Length - 2);///
                                ///
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal,
                                                              this.f_splitString3Column(aNHOMHANG[0], iTHANHTIENTRUOC.ToString("N0") , iTIENMAT.ToString("N0")));

                                if (aNHOMHANG.Length > 1)// in dong thu 2 NHOM_HANG
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, aNHOMHANG[1]);

                                if (i != tb.Rows.Count - 1)
                                    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                            }

                        }
                        #endregion

                        #region "   4.BAO CAO DOANH THU MAT HANG - tb = ds.Tables[5]"
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        tb = null;
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU MAT HANG", "", "", "");
                        //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);


                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        //==================================================DETAIL====================================================================
                        //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Stt", "Mat hang", "T tien", "Ch lech", "Tien mat", "Ty le");
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, this.f_splitString3Column("Mat hang", "S luong  ", "Tien mat"), "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                        //========================================================
                        tb = ds.Tables[5]; // nhom hang hoa
                        if (tb.Rows.Count > 0)
                        {
                            string sHANGHOA = "";
                            cpublic ocpublic = new cpublic();
                            for (int i = 0; i < tb.Rows.Count; i++)
                            {
                                sHANGHOA = tb.Rows[i]["HANGHOA"] + "";
                                if (sHANGHOA.Trim() == "")
                                {
                                    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                    continue;
                                }
                                int iSOLUONG = 0;
                                int.TryParse(tb.Rows[i]["SOLUONG"] + "", out iSOLUONG);
                                int iTIENMAT = 0;
                                int.TryParse(tb.Rows[i]["TIENMAT"] + "", out iTIENMAT);
                                float iTYLE = 0;
                                float.TryParse(tb.Rows[i]["TYLE"] + "", out iTYLE);
                                string[] aHANGHOA = ocpublic.splitString(sHANGHOA, 32 - iSOLUONG.ToString("N0").Length - 2);///

                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal,
                                                         this.f_splitString3Column(aHANGHOA[0], iSOLUONG.ToString("N0") , iTIENMAT.ToString("N0")), "", "", "");

                                if (aHANGHOA.Length > 1)//20110315
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, aHANGHOA[1]);
                            }
                        }
                        #endregion

                        if (1 == 2 + 3)//PACIFIC ko in phan nay
                        {
                            #region "   5.BAO CAO DOANH THU KHU VUC - tb = ds.Tables[7]"
                            //          khu vuc
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            tb = null;
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU KHU VUC", "", "", "");
                            //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);


                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                            //==================================================DETAIL====================================================================
                            //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Stt", "Mat hang", "T tien", "Ch lech", "Tien mat", "Ty le");
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, this.f_splitString4Column("Khu vuc", "T tien   ", "Ch lech", "Tien mat"), "", "", "");
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                            //========================================================
                            tb = ds.Tables[7];
                            for (int i = 0; i < tb.Rows.Count; i++)
                            {
                                if (tb.Rows[i]["THANHTIENTRUOC"] + "" == "")
                                {
                                    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                    continue;
                                }
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal,
                                                            this.f_splitString4Column(tb.Rows[i]["TENBAN"] + "", (int.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0") + "   ",
                                                           (int.Parse(tb.Rows[i]["CHENHLECH"] + "")).ToString("N0"), (int.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0")), "", "", "");
                                //, tb.Rows[i]["TYLE"] + "");

                                if (i != tb.Rows.Count - 1)
                                    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                            }
                            #endregion

                            #region "   6.BAO CAO DOANH THU BAN - tb = ds.Tables[9]"
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            tb = null;
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU BAN", "", "", "");

                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);



                            //==================================================DETAIL====================================================================

                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, this.f_splitString4Column("Khu vuc", "T tien   ", "Ch lech", "Tien mat"), "", "", "");
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                            //========================================================
                            tb = ds.Tables[9];
                            if (tb.Rows.Count > 0)
                            {
                                string sHANGHOA = "";
                                cpublic ocpublic = new cpublic();
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    sHANGHOA = tb.Rows[i]["HANGHOA"] + "";
                                    if (tb.Rows[i]["THANHTIENTRUOC"] + "" == "")
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        continue;
                                    }
                                    string[] aHANGHOA = ocpublic.splitString(sHANGHOA, 32 - (int.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0").Length - 3);///
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal,
                                                                this.f_splitString4Column(aHANGHOA[0], (int.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0") + "   ",
                                                               (int.Parse(tb.Rows[i]["CHENHLECH"] + "")).ToString("N0"), (int.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0")), "", "", "");
                                    if (aHANGHOA.Length > 1)//20110315
                                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, aHANGHOA[1]);

                                }
                            }
                            #endregion
                        }

                        #region "   7.FOOTER"
                        //=======================================FOOTER===============================================================================
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                        oPrintCOMs.Print_Bottom(oSerialPort_LPV);
                        oPrintCOMs.Print_Close();
                        #endregion

                    }
                }
                #endregion
            }
        }
        catch (Exception ex)
        {
            MessageBox_LPV.Show("Thông báo\n" + ex.Message);
        }
        finally {
            //System.Windows.Forms.Cursor = System.Windows.Forms.Cursors.Default;
        }
    }

    #region "   f_splitString4Column"
    string f_splitString4Column(string a, string b, string c, string d)
    {//56
        int i1 = 36;
        int i2 = 10;
        int i3 = 10;
        string str = "";
        cpublic ocpublic = new cpublic();
        a = ocpublic.RemoveSign4VietnameseString(a).Trim();
        str = a;
        str += ocpublic.Spacestring(i1 - a.Length - b.Length);
        str += b;
        str += ocpublic.Spacestring(i2 - c.Length);
        str += c;
        str += ocpublic.Spacestring(i3 - d.Length);
        str += d;
        return str;
    }
    #endregion

    #region "   f_splitString3Column"
    string f_splitString3Column(string a, string b, string c)
    {//i1: 29; i2:13
        int i1 = 29;
        int i2 = 13;
        string str = "";
        cpublic ocpublic = new cpublic();
        a = ocpublic.RemoveSign4VietnameseString(a).Trim();
        str = a;
        str += ocpublic.Spacestring(i1 - a.Length - b.Length);
        str += b;
        str += ocpublic.Spacestring(i2 - c.Length);
        str += c;
        return str;
    }
    #endregion
}
